package com.yincai.carefreewater.tool;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

/**
 * Created by $zhangke on 2017/4/12.
 *
 */

public class DateTimeUtil {

    public static String getTime(int year, int month){

        Calendar calendar= Calendar.getInstance();
        calendar.set(year,month,1);
        long  time=calendar.getTimeInMillis()/1000;
        return  time+"";
    }
    public static String getTime(String date){

        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        long  time=0;
        try {
            time=sdf.parse(date).getTime()/1000;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time+"";
    }

    public static String getTime(Calendar calendar){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        return  sdf.format(calendar.getTime());
    }
    public static String getTime(int year, int month, int day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);
        return sdf.format(calendar.getTime());
    }
    public static String getTime(long str){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(str*1000);
        return  sdf.format(calendar.getTime());
    }
    public static String getTime(){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        return  sdf.format(calendar.getTime());
    }

    /**
     * int stime, 时间段
     * int etime
     * @return
     *  匹配特定时间点
     */
    public static   boolean  getUpTime(int stime,int etime){
        Calendar calendar=Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
       if(hour>=stime&&hour<etime){
           return true;
       }else {
           return false;
       }
    }

    /**
     * @return
     * 随机时间点
     */
    public static   int  getMint(){
        Random random=new Random(49);
        int i = random.nextInt()+1;
        return  i;
    }

    /**
     * @return
     * 随机小时
     */
    public static   int  gethour(){
        Random random=new Random(2);
        int i = random.nextInt()+1;
        return  i;
    }


}
